package com.xhs.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;

/**
 * Playwright配置类
 *
 * @author xhs
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "playwright")
public class PlaywrightConfig {

    @Autowired
    private ProxyConfig proxyConfig;

    /**
     * 会话超时时间（毫秒）
     */
    private Long sessionTimeout = 300000L;

    /**
     * 最大并发浏览器数量
     */
    private Integer maxConcurrentBrowsers = 10;

    /**
     * 是否开启无头模式
     */
    private Boolean headless = false;

    /**
     * 页面默认超时时间（毫秒）
     */
    private Long pageTimeout = 20000L;

    /**
     * 元素等待超时时间（毫秒）
     */
    private Long elementTimeout = 8000L;

    /**
     * 网络请求超时时间（毫秒）
     */
    private Long networkTimeout = 15000L;

    /**
     * 慢速模式延迟时间（毫秒）
     */
    private Long slowMo = 500L;

    /**
     * 浏览器用户代理
     */
    private String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";

    /**
     * 视口宽度
     */
    private Integer viewportWidth = 1920;

    /**
     * 视口高度
     */
    private Integer viewportHeight = 1080;

    /**
     * 额外的HTTP头
     */
    private Map<String, String> extraHttpHeaders = Map.of(
        "Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8"
    );

    /**
     * headless模式下的浏览器参数
     */
    private List<String> headlessArgs = List.of(
        "--no-sandbox",
        "--disable-dev-shm-usage",
        "--disable-gpu",
        "--disable-web-security",
        "--disable-features=VizDisplayCompositor",
        "--disable-extensions",
        "--disable-plugins",
        "--disable-background-timer-throttling",
        "--disable-backgrounding-occluded-windows",
        "--disable-renderer-backgrounding",
        "--disable-blink-features=AutomationControlled",
        "--disable-infobars",
        "--no-first-run",
        "--no-default-browser-check"
    );

    /**
     * 是否忽略HTTPS错误
     */
    private Boolean ignoreHttpsErrors = true;

    /**
     * headless模式下是否启用JavaScript
     */
    private Boolean headlessJavaScriptEnabled = true;

    /**
     * 操作等待时间（毫秒）
     */
    private Long actionWaitTime = 1000L;

    /**
     * headless模式下的操作等待时间（毫秒）
     */
    private Long headlessActionWaitTime = 3000L;

    /**
     * 获取代理配置
     */
    public ProxyConfig getProxyConfig() {
        return proxyConfig;
    }
} 